package com.jerkin.mynlp;

import com.mayabot.nlp.module.summary.KeywordSummary;
import com.mayabot.nlp.segment.FluentLexerBuilder;
import com.mayabot.nlp.segment.Lexer;
import com.mayabot.nlp.segment.LexerReader;
import com.mayabot.nlp.segment.Lexers;
import com.mayabot.nlp.segment.plugins.customwords.CustomDictionaryPlugin;
import com.mayabot.nlp.segment.plugins.customwords.MemCustomDictionary;

/**
 * @description:
 * @className:LexerFactory
 * @author:huhongzhi
 * @createTime:2021/3/18 14:58
 * @version:1.0
 */
public class LexerFactory {


    private static class LexerHolder {

        private static Lexer LEXERS = null;
        private static KeywordSummary keywordSummary = null;

        static {
            MemCustomDictionary dictionary = new MemCustomDictionary();
            dictionary.addWord("蘑菇钉");
            dictionary.addWord("易拉宝");
            dictionary.addWord("铲雪刷");
            dictionary.addWord("电吹风机");
            dictionary.addWord("火花塞");
            dictionary.addWord("滤清器");
            dictionary.addWord("圆形塞尺");
            dictionary.addWord("广告衫");
            dictionary.addWord("京东卡");
            dictionary.addWord("京东礼品卡");
            dictionary.addWord("抓绒衫");
            dictionary.rebuild();

            FluentLexerBuilder builder = Lexers.coreBuilder()
                    .withPos()
                    .with(new CustomDictionaryPlugin(dictionary))
                    .withPersonName()
                    .withNer();

            LEXERS = builder.build();
            keywordSummary = new KeywordSummary();
            keywordSummary.setLexerReader(LexerReader.from(LEXERS));
        }
    }

    public static Lexer getInstance() {
        return LexerHolder.LEXERS;
    }

    public static KeywordSummary getKeyWordSummary() {
        return LexerHolder.keywordSummary;
    }
}